package com.lei.zjs.service.ebo;

import java.util.List;

import javax.annotation.Resource;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lei.zjs.dao.RoleDao;
import com.lei.zjs.service.ebi.RoleService;
import com.lei.zjs.vo.Function;
import com.lei.zjs.vo.Role;

@Service
@Transactional
public class RoleServiceImpl implements RoleService{

	@Resource
	private RoleDao roleDao;
	@Resource
	private ProcessEngine processEngine;

	@Override
	public void save(Role role, String functionIds) {
		Group group = new GroupEntity();
		group.setId(role.getName());
		processEngine.getIdentityService().saveGroup(group);
		roleDao.save(role);
		String[] ids = functionIds.split(",");
		for (String id : ids) {
			Function function = new Function();
			function.setId(id);
			role.getFunctions().add(function);
		}
	}

	@Override
	public List<Role> findAll() {
		return roleDao.findAll();
	}
}
